package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 高级计算二级枚举
 * @author xinpeng.jiang
 * @version V1.0
 * @date 2021/6/4 10:10
 * @since V1.0
 */
@Getter
public enum AdvancedComputingSecondEnum {
    /**
     * 同比增长值
     */
    YEAR_VALUE(1, AdvancedComputingFirstEnum.YEAR_CHAIN, "enum.advancedComputingSecond.name.yearValue", "yearValue"),
    /**
     * 同比增长率
     */
    YEAR_RATE(2, AdvancedComputingFirstEnum.YEAR_CHAIN, "enum.advancedComputingSecond.name.yearRate", "yearRate"),
    /**
     * 环比增长值
     */
    CHAIN_VALUE(3, AdvancedComputingFirstEnum.YEAR_CHAIN, "enum.advancedComputingSecond.name.chainValue", "chainValue"),
    /**
     * 环比增长率
     */
    CHAIN_RATE(4, AdvancedComputingFirstEnum.YEAR_CHAIN, "enum.advancedComputingSecond.name.chainRate", "chainRate"),
    ;

    private final Integer code;
    /**
     * 父类,在AdvancedComputingFirstEnum中
     */
    private final AdvancedComputingFirstEnum parentType;

    private final String name;

    private final String alias;

    AdvancedComputingSecondEnum(Integer code, AdvancedComputingFirstEnum parentType, String name, String alias) {
        this.code = code;
        this.parentType = parentType;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 判断是比值还是比率，-1都不是 1比值 2比率
     * @param alias
     * @return java.lang.Integer
     * @author xinpeng.jiang
     * @date 2021/6/10 9:41
     * @version 1.0
     */
    public static Integer getValueOrRate(String alias) {
        if (Objects.equals(alias, YEAR_VALUE.getAlias()) || Objects.equals(alias, CHAIN_VALUE.getAlias())) {
            return ValueRateEnum.VALUE.getValue();
        }
        if (Objects.equals(alias, YEAR_RATE.getAlias()) || Objects.equals(alias, CHAIN_RATE.getAlias())) {
            return ValueRateEnum.RATE.getValue();
        }
        return ValueRateEnum.UNKNOWN.getValue();
    }

    /**
     * 判断是同比还是环比，-1都不是 1同比 2环比
     * @param alias
     * @return java.lang.Integer
     * @author xinpeng.jiang
     * @date 2021/6/10 9:41
     * @version 1.0
     */
    public static Integer getYearOrChain(String alias) {
        if (Objects.equals(alias, YEAR_VALUE.getAlias()) || Objects.equals(alias, YEAR_RATE.getAlias())) {
            return YearChainEnum.YEAR_ON_YEAR.getValue();
        }
        if (Objects.equals(alias, CHAIN_VALUE.getAlias()) || Objects.equals(alias, CHAIN_RATE.getAlias())) {
            return YearChainEnum.CHAIN_ON_CHAIN.getValue();
        }
        return YearChainEnum.UNKNOWN.getValue();
    }

    /**
     * 通过别名获取AdvancedComputingSecondEnum
     * @param alias 别名
     * @return
     * @throws
     *
     * @author mengna.deng
     * @since v1.0
     * @version v1.0
     */
    public static AdvancedComputingSecondEnum getByAlias(String alias) {
        for (AdvancedComputingSecondEnum secondEnum : values()) {
            if (Objects.equals(secondEnum.getAlias(), alias)) {
                return secondEnum;
            }
        }
        return null;
    }

    /**
     * 通过别名获取国际化后的name
     * @param alias
     * @return
     * @author 梅伟丁
     * @date 2022/5/17 10:21:26
     * @version 1.0
     */
    public static String getNameByAlias(String alias) {
        for (AdvancedComputingSecondEnum secondEnum : values()) {
            if (Objects.equals(secondEnum.getAlias(), alias)) {
                return secondEnum.getName();
            }
        }
        return null;
    }

    public String getName(){
        return I18nMessageUtil.getMessage(name);
    }
}
